import 'base_model.dart';

class UserFollow implements BaseModel {
  final int? id;
  final int followerId;
  final int followingId;
  final DateTime createdAt;
  final DateTime updatedAt;

  UserFollow({
    this.id,
    required this.followerId,
    required this.followingId,
    required this.createdAt,
    required this.updatedAt,
  });

  @override
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'follower_id': followerId,
      'following_id': followingId,
      'created_at': createdAt.millisecondsSinceEpoch,
      'updated_at': updatedAt.millisecondsSinceEpoch,
    };
  }

  factory UserFollow.fromJson(Map<String, dynamic> json) {
    return UserFollow(
      id: json['id'],
      followerId: json['follower_id'],
      followingId: json['following_id'],
      createdAt: DateTime.fromMillisecondsSinceEpoch(json['created_at']),
      updatedAt: DateTime.fromMillisecondsSinceEpoch(json['updated_at']),
    );
  }

  // 复制对象并修改指定字段
  UserFollow copyWith({
    int? id,
    int? followerId,
    int? followingId,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return UserFollow(
      id: id ?? this.id,
      followerId: followerId ?? this.followerId,
      followingId: followingId ?? this.followingId,
      createdAt: createdAt ?? this.createdAt,
      updatedAt: updatedAt ?? this.updatedAt,
    );
  }
}
